package com.meida.module.bus.provider.service.srmservice;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.google.common.collect.Maps;
import com.meida.module.bus.client.entity.srmapi.basedata.*;
import com.meida.module.bus.provider.mapper.srm.SrmSqlserCommonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * SRM项目信息表接口实现类
 *
 * @author both
 * @date 2020-10-14
 */
@Service
@DS("dbr")
public class SrmSqlserCommonService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Resource
    private SrmSqlserCommonMapper srmSqlserCommonMapper;

    public Object getDatas(String tableNm, Class name) {
        String sqlCount = "select count(*) from " + tableNm;
        Long count = jdbcTemplate.queryForObject(sqlCount, Long.class);
        if (0L == count) {
            return new ArrayList<>();
        }

        BeanPropertyRowMapper<Object> rowMapper = new BeanPropertyRowMapper<>(name);
        String sqlContent = "select * from " + tableNm;
        return jdbcTemplate.query(sqlContent, rowMapper);
    }

    public SrmContracts getSrmContract(Map<String, Object> pamams) {
        return srmSqlserCommonMapper.getSrmContract(pamams);
    }

    public List<SrmContracts> getSrmContracts(Map<String, Object> pamams) {
        return srmSqlserCommonMapper.getSrmContracts(pamams);
    }

    public List<SrmContractsmatdtl> getSrmContractsmatdtl(Map<String, Object> pamams) {
        return srmSqlserCommonMapper.getSrmContractsmatdtl(pamams);
    }

    public List<SrmContractsmatdtl> getSrmContractsmatdtlByIds(Long ids[]) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("ids", ids);
        return srmSqlserCommonMapper.getSrmContractsmatdtl(params);
    }

    public List<SrmDelivery> getSrmDelivery(Map<String, Object> pamams) {
        return srmSqlserCommonMapper.getSrmDelivery(pamams);
    }

    public List<SrmDeliverydtl> getSrmDeliverydtl(Map<String, Object> pamams) {
        return srmSqlserCommonMapper.getSrmDeliverydtl(pamams);
    }

    public List<SrmDemandplan> getSrmDemandplan(Map<String, Object> pamams) {
        return srmSqlserCommonMapper.getSrmDemandplan(pamams);
    }

    public List<SrmDemandplandtl> getSrmDemandplandtl(Map<String, Object> pamams) {
        return srmSqlserCommonMapper.getSrmDemandplandtl(pamams);
    }

    public List<SrmMaterial> getSrmMaterial(Map<String, Object> pamams) {
        return srmSqlserCommonMapper.getSrmMaterial(pamams);
    }

    public List<SrmPurchaseorder> getSrmPurchaseorder(Map<String, Object> pamams) {
        return srmSqlserCommonMapper.getSrmPurchaseorder(pamams);
    }

    public List<SrmPurchaseorderdetail> getSrmPurchaseorderdetail(Map<String, Object> pamams) {
        return srmSqlserCommonMapper.getSrmPurchaseorderdetail(pamams);
    }

    public List<SrmPurchaseorderdetail> getSrmPurchaseorderdetailByIds(Long ids[]) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("ids", ids);
        return srmSqlserCommonMapper.getSrmPurchaseorderdetail(params);
    }

    public List<SrmPurchasingrequisition> getSrmPurchasingrequisition(Map<String, Object> pamams) {
        return srmSqlserCommonMapper.getSrmPurchasingrequisition(pamams);
    }

    public List<SrmPurchasingrequisitiondtl> getSrmPurchasingrequisitiondtl(Map<String, Object> pamams) {
        return srmSqlserCommonMapper.getSrmPurchasingrequisitiondtl(pamams);
    }

    public List<SrmReceivingnote> getSrmReceivingnote(Map<String, Object> pamams) {
        return srmSqlserCommonMapper.getSrmReceivingnote(pamams);
    }

    public List<SrmVendor> getSrmVendor(Map<String, Object> pamams) {
        return srmSqlserCommonMapper.getSrmVendor(pamams);
    }

    public List<SrmWbsarchitecture> getSrmWbsarchitecture(Map<String, Object> pamams) {
        return srmSqlserCommonMapper.getSrmWbsarchitecture(pamams);
    }

    public List<SrmProjectinfo> getSrmProjectIno(Map<String, Object> pamams) {
        return srmSqlserCommonMapper.getSrmProjectIno(pamams);
    }

//    public Object[] getData(String tabNm) {
//        return srmSqlserCommonMapper.getData(tabNm);
//    }
}
